{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#Snippets and Programs from Chapter 5: Playing with Sets and Probability"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{EmptySet(), {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}}"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#P125: Finding the power set of a set\n",
    ">>> from sympy import FiniteSet\n",
    ">>> s = FiniteSet(1, 2, 3)\n",
    ">>> ps = s.powerset()\n",
    ">>> ps"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1, 2, 3, 4, 6}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#P126: Union of two Sets\n",
    ">>> from sympy import FiniteSet \n",
    ">>> s = FiniteSet(1, 2, 3)\n",
    ">>> t = FiniteSet(2, 4, 6)\n",
    ">>> s.union(t)\n",
    "{1, 2, 3, 4, 6}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{2}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#P127: Intersection of two Sets\n",
    ">>> from sympy import FiniteSet\n",
    ">>> s = FiniteSet(1, 2) \n",
    ">>> t = FiniteSet(2, 3) \n",
    ">>> s.intersect(t)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1, 3)\n",
      "(1, 4)\n",
      "(2, 3)\n",
      "(2, 4)\n"
     ]
    }
   ],
   "source": [
    "#P127/128: Cartesian product of two Sets\n",
    ">>> from sympy import FiniteSet \n",
    ">>> s = FiniteSet(1, 2)\n",
    ">>> t = FiniteSet(3, 4)\n",
    ">>> p = s*t\n",
    ">>> for elem in p:\n",
    "        print(elem)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Length(cm)   Gravity(m/s^2) Time Period(s) \n",
      "     15.0           9.78           0.778     \n",
      "     15.0            9.8           0.777     \n",
      "     15.0           9.83           0.776     \n",
      "     18.0           9.78           0.852     \n",
      "     18.0            9.8           0.852     \n",
      "     18.0           9.83           0.850     \n",
      "     21.0           9.78           0.921     \n",
      "     21.0            9.8           0.920     \n",
      "     21.0           9.83           0.918     \n",
      "     22.5           9.78           0.953     \n",
      "     22.5            9.8           0.952     \n",
      "     22.5           9.83           0.951     \n",
      "     25.0           9.78           1.005     \n",
      "     25.0            9.8           1.004     \n",
      "     25.0           9.83           1.002     \n"
     ]
    }
   ],
   "source": [
    "#P130: Different gravity, different results\n",
    "from sympy import FiniteSet, pi\n",
    "def time_period(length, g):\n",
    "    T = 2*pi*(length/g)**0.5\n",
    "    return T\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    L = FiniteSet(15, 18, 21, 22.5, 25)\n",
    "    g_values = FiniteSet(9.8, 9.78, 9.83)\n",
    "    print('{0:^15}{1:^15}{2:^15}'.format('Length(cm)', 'Gravity(m/s^2)', 'Time Period(s)'))\n",
    "    for elem in L*g_values:\n",
    "        l = elem[0]\n",
    "        g = elem[1]\n",
    "        t = time_period(l/100, g)\n",
    "        print('{0:^15}{1:^15}{2:^15.3f}'.format(float(l), float(g), float(t)))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Sample space: {1, 2, 3, ..., 18, 19, 20}\n",
      "Event: {2, 3, 5, 7, 11, 13, 17, 19}\n",
      "Probability of rolling a prime: 0.40000\n"
     ]
    }
   ],
   "source": [
    "#P132: Probability of a Prime number appearing when a 20-sided dice is rolled\n",
    "def probability(space, event):\n",
    "    return len(event)/len(space)\n",
    "\n",
    "def check_prime(number): \n",
    "    if number != 1:\n",
    "        for factor in range(2, number):\n",
    "            if number % factor == 0:\n",
    "                return False\n",
    "    else:\n",
    "        return False\n",
    "    return True\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    space = FiniteSet(*range(1, 21))\n",
    "    primes = []\n",
    "    for num in space:\n",
    "        if check_prime(num):\n",
    "            primes.append(num)\n",
    "    event= FiniteSet(*primes)\n",
    "    p = probability(space, event)\n",
    "    print('Sample space: {0}'.format(space))\n",
    "    print('Event: {0}'.format(event))\n",
    "    print('Probability of rolling a prime: {0:.5f}'.format(p))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6666666666666666"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#P134: Probability of event A or event B\n",
    ">>> from sympy import FiniteSet\n",
    ">>> s = FiniteSet(1, 2, 3, 4, 5, 6) \n",
    ">>> a = FiniteSet(2, 3, 5)\n",
    ">>> b = FiniteSet(1, 3, 5)\n",
    ">>> e = a.union(b) \n",
    ">>> len(e)/len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.3333333333333333"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#P134: Probability of event A and event B\n",
    ">>> from sympy import FiniteSet\n",
    ">>> s = FiniteSet(1, 2, 3, 4, 5, 6) \n",
    ">>> a = FiniteSet(2, 3, 5)\n",
    ">>> b = FiniteSet(1, 3, 5)\n",
    ">>> e = a.intersect(b)\n",
    ">>> len(e)/len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Rolled: 5\n",
      "Rolled: 4\n",
      "Rolled: 2\n",
      "Rolled: 5\n",
      "Rolled: 2\n",
      "Rolled: 6\n",
      "Score of 24 reached in 6 rolls\n"
     ]
    }
   ],
   "source": [
    "#P135: Can you Roll that score?\n",
    "\n",
    "'''\n",
    "Roll a die until the total score is 20\n",
    "'''\n",
    "import matplotlib.pyplot as plt\n",
    "import random\n",
    "\n",
    "target_score = 20\n",
    "def roll():\n",
    "    return random.randint(1, 6)\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    score = 0\n",
    "    num_rolls = 0\n",
    "    while score < target_score:\n",
    "        die_roll = roll()\n",
    "        num_rolls += 1\n",
    "        print('Rolled: {0}'.format(die_roll))\n",
    "        score += die_roll\n",
    "    print('Score of {0} reached in {1} rolls'.format(score, num_rolls))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enter the target score: 25\n",
      "Enter the maximum number of rolls allowed: 5\n",
      "Probability:  0.03241\n"
     ]
    }
   ],
   "source": [
    "#P136: Is the target score possible?\n",
    "from sympy import FiniteSet\n",
    "import random\n",
    "def find_prob(target_score, max_rolls):\n",
    "    die_sides = FiniteSet(1, 2, 3, 4, 5, 6)\n",
    "    # sample space\n",
    "    s = die_sides**max_rolls\n",
    "    # Find the event set\n",
    "    if max_rolls > 1:\n",
    "        success_rolls = []\n",
    "        for elem in s:\n",
    "            if sum(elem) >= target_score:\n",
    "                success_rolls.append(elem)\n",
    "    else:\n",
    "        if target_score > 6:\n",
    "            success_rolls = []\n",
    "        else:\n",
    "            success_rolls = []\n",
    "            for roll in die_sides:\n",
    "                if roll >= target_score:\n",
    "                    success_rolls.append(roll)\n",
    "    e = FiniteSet(*success_rolls)\n",
    "    # calculate the probability of reaching target score\n",
    "    return len(e)/len(s)\n",
    "if __name__ == '__main__':\n",
    "    target_score = int(input('Enter the target score: '))\n",
    "    max_rolls  = int(input('Enter the maximum number of rolls allowed: '))\n",
    "    p = find_prob(target_score, max_rolls)\n",
    "    print('Probability:  {0:.5f}'.format(p))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAEACAYAAAC08h1NAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAFCRJREFUeJzt3V2MXOd93/HvTy+EZZuqKqigKImFeUEDZuBGMhMzqN14\nXcMCVbSSfCPJQBUiUQMXjF/QIkFFX1SrBIjTAHatoJBuLEek2rAgEpigY0UWpYqocxEt7JISLVqV\nFJiBdyuuUlQ1pQhGJejfizlrjlfDfeNyzljP9wMc7DPPOWfOf56d+c3ZZ142VYUkqR0X9V2AJGm8\nDH5JaozBL0mNMfglqTEGvyQ1xuCXpMYsGfxJ3pXkqSTHk5xM8qWufzrJbJJj3XLT0D57k7yQ5Lkk\nNw7170hyolt334W7SZKkpWS59/EneXdVvZ7kEuAvgd8GPgG8WlVfWbTtduBPgF8GrgUeB7ZVVSWZ\nAT5bVTNJHgH+qKoeXf+bJElayrJTPVX1etfcAFwMvNJdzojNbwEOVNUbVXUKeBHYmWQzsLGqZrrt\n9gO3nk/hkqS1WTb4k1yU5DgwDzxZVc92qz6X5OkkDya5ouu7Bpgd2n2WwZn/4v65rl+SNGYrOeN/\nq6quB64DfjXJFPAAsBW4HngJ+PKFLFKStH4uWemGVfXjJN8Cfqmqji70J/ka8M3u4hywZWi36xic\n6c917eH+ucXHSOIXB0nSGl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xz/LDRsAAAAAElF\nTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1065b79b0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#P139: Simulate a fictional ATM\n",
    "'''\n",
    "Simulate a fictional ATM that dispenses dollar bills\n",
    "of various denominations with varying probability\n",
    "'''\n",
    "\n",
    "import random\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "def get_index(probability):\n",
    "    c_probability = 0\n",
    "    sum_probability = []\n",
    "    for p in probability:\n",
    "        c_probability += p\n",
    "        sum_probability.append(c_probability)\n",
    "    r = random.random()\n",
    "    for index, sp in enumerate(sum_probability):\n",
    "        if r <= sp:\n",
    "            return index\n",
    "    return len(probability)-1\n",
    "\n",
    "def dispense():\n",
    "    dollar_bills = [5, 10, 20, 50]\n",
    "    probability = [1/6, 1/6, 1/3, 1/3]\n",
    "    bill_index = get_index(probability)\n",
    "    return dollar_bills[bill_index]\n",
    "\n",
    "# Simulate a large number of bill withdrawls\n",
    "if __name__ == '__main__':\n",
    "    bill_dispensed = []\n",
    "    for i in range(10000):\n",
    "        bill_dispensed.append(dispense())\n",
    "    # plot a histogram \n",
    "    plt.hist(bill_dispensed)\n",
    "    plt.show()\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAQEAAADyCAYAAABNnXD+AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAHK1JREFUeJzt3XuMnNd53/Hvmeveb+SSuySXoiRSJHW/UpQombFsw6nj\nOEWANEVQ2C2aAkGBwEFbu02ddMq4SFrETWC7CFIEjuG0DVDErg0lQBJHliXZlihSF0qkSPFi3skl\nd5fL5e7O7tzeOf3j7MqUxN2dnTnznvPO+3yAwUIC8c6z5Ly/Oe+5Kq01Qoj4SrguQAjhloSAEDEn\nISBEzE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FoCEaaU+lvgiNb6Cx/4\n/78CfBXTQSgn+4plSQgIEXPyOCBEzEkICBFzEgJCxJyEgBAxJyEgRMxJCAgRcxICQsSchIAQMSch\nIETM/X8fFK7gq8MGhwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x107665b00>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#P140: Draw a Venn diagram for two sets\n",
    "'''\n",
    "Draw a Venn diagram for two sets\n",
    "'''\n",
    "from matplotlib_venn import venn2\n",
    "import matplotlib.pyplot as plt\n",
    "from sympy import FiniteSet\n",
    "def draw_venn(sets):\n",
    "    venn2(subsets=sets)    \n",
    "    plt.show()\n",
    "    \n",
    "if __name__ == '__main__':\n",
    "    s1 = FiniteSet(1, 3, 5, 7, 9, 11, 13, 15, 17, 19)\n",
    "    s2 = FiniteSet(2, 3, 5, 7, 11, 13, 17, 19)\n",
    "    draw_venn([s1, s2])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.4.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
